@extends('common.base-master')

@section('html-title')
    <title>论坛</title>
@endsection

@section('html-head')
    <link rel="stylesheet" href="{{url('css/public.css')}}">
    <link rel="stylesheet" href="{{url('css/common.css')}}">
    <link rel="stylesheet" href="{{url('forum_tmp/reset.css')}}">
    <link rel="stylesheet" href="{{url('forum_tmp/global.css')}}">
    <style>
        body{
            background-color: #f4f4f4;
        }
    </style>
@endsection

@section('html-body')
    <div class="writeHead">
        <div class="writeHead_top center">
            <a href="{{route('Home.Page.forumHome')}}"><img src="{{url('forum_tmp/backIcon.png')}}" alt="" class="backBtn"></a>
            <h1>帖子列表</h1>
        </div>
    </div>
    <div style="width: 100%;height: 46px"></div>
    <div class="lt_contentTop">
        <h1 class="lt_contentTop_Title">{{$forum->title}}</h1>
        <div class="lt_contentTop_Msg">
                <div class="ltConPic">
                    <img src="{{$forum->user_info->photo_url}}" alt="">
                </div>
                <p>{{$forum->user_info->nickname}}</p>
        </div>
        <img src="{{$forum->img_url}}" style="width: 100%;margin-top: 10px" />
        <div class="ltCon_detail">
            <p><?php if($forum){echo html_entity_decode($forum->content);} ?></p>
        </div>
        <div class="ltDo" data-id="0" data-to="">
            <span>评论</span>
        </div>
    </div>
    <div class="ltCon_pend">
        <p class="ltCon_pendFont center">评论区</p>

        @if(count($allForumDiscuss) > 0)
            @foreach($allForumDiscuss as $forumDiscus)
        <div class="ltCon_pendCen center">
            <div class="ltCon_pendCen_left">
{{--
                <img src="{{$forumDiscus->from_user_info->photo_url}}" alt="">
--}}
                <img src="{{$forumDiscus->photo_url}}" alt="">
            </div>
            <div class="ltCon_pendCen_right">
{{--
                <h6>{{$forumDiscus->from_user_info->nickname}}</h6>
--}}
                <h6>{{$forumDiscus->from_user_nickname}}</h6>
{{--
                <span>{{\App\Http\Services\Tools::simpleTimestamp(strtotime($forumDiscus->created_at))}}</span>
--}}
                <div class="clear"></div>
                <p class="ltReplay">@if(!is_null($forumDiscus->to_user_info))[回复 {{$forumDiscus->to_user_info->nickname}}]@endif {{$forumDiscus->content}}</p>
{{--
                <div class="ltDo" data-id="{{$forumDiscus->id}}" data-to="{{$forumDiscus->from_user_info->nickname}}">
--}}
                <div class="ltDo" data-id="{{$forumDiscus->id}}" data-to="{{$forumDiscus->from_user_nickname}}">
                    <span>回复</span>
                </div>
            </div>
        </div>
            @endforeach
        @endif
    </div>
    <div style="width: 100%;height: 50px"></div>
    <div class="ltConFoot">
        <div class="ltConFoot_cen center">
            <input type="hidden" id="fid" value="{{$forum->id}}">
            <input type="hidden" id="pid" value="0">
            <input type="text" placeholder="说说您看法" id="send_content">
            <input type="submit" value="" id="btn_send">
        </div>
    </div>
    <script>
        $(function () {
            // $(document).on("click",".ltDo",function () {
            //     var pid        = $(this).data("id");
            //     var toNickname = $(this).data("to");
            //     $("#send_content").focus();
            //     if(pid !="" && parseInt(pid) != 0){
            //         $("#send_content").attr("placeholder","回复@"+toNickname);
            //         $("#pid").val(pid);
            //     }else {
            //         $("#send_content").attr("placeholder","说说您看法");
            //         $("#pid").val(0);
            //     }
            // });

            $(".ltDo").click(function () {
                var pid        = $(this).data("id");
                var toNickname = $(this).data("to");
                $("#send_content").focus();
                if(pid !="" && parseInt(pid) != 0){
                    $("#send_content").attr("placeholder","回复@"+toNickname);
                    $("#pid").val(pid);
                }else {
                    $("#send_content").attr("placeholder","说说您看法");
                    $("#pid").val(0);
                }
            })

            $(document).on("click","#btn_send",function () {
                var pid = $("#pid").val();
                var fid = $("#fid").val();
                var content = $("#send_content").val();
                $.showLoading("发送中...");
                $.ajax({
                    url:"{{route('Api.Forum.setUserContent')}}",
                    type:"post",
                    dataType:"json",
                    data:{f_id:fid,pid:pid,content:content},
                    success:function (obj) {
                        $.hideLoading();
                        if(obj.level == "success"){
                            window.location.reload();
                        }else {
                            $.toast(obj.message, "forbidden");
                        }
                    },
                    error:function (obj) {
                        $.hideLoading();
                        $.toast(obj.message, "forbidden");
                    }
                });
            });
        })
    </script>
@endsection